package cn.xy.demo03;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler{

    private Object object;

    public void setObject(Object object) {
        this.object = object;
    }

    //生成代理类
    public Object getObject() {
        Proxy.newProxyInstance(this.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
        return object;
    }

    //执行被代理的类的方法
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(object, args);
        return result;
    }
}
